<!DOCTYPE html>
<html>

<head>
  <title>Chats Protocols - AIL</title>
	<link rel="icon" href="{{ url_for('static', filename='image/ail-icon.png') }}">

  <!-- Core CSS -->
	<link href="{{ url_for('static', filename='css/bootstrap4.min.css') }}" rel="stylesheet">
	<link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet">
	<link href="{{ url_for('static', filename='css/dataTables.bootstrap.min.css') }}" rel="stylesheet">

  <!-- JS -->
	<script src="{{ url_for('static', filename='js/jquery.js')}}"></script>
	<script src="{{ url_for('static', filename='js/popper.min.js')}}"></script>
	<script src="{{ url_for('static', filename='js/bootstrap4.min.js')}}"></script>
	<script src="{{ url_for('static', filename='js/jquery.dataTables.min.js')}}"></script>
	<script src="{{ url_for('static', filename='js/dataTables.bootstrap.min.js')}}"></script>

</head>
<body>

	{% include 'nav_bar.html' %}

	<div class="container-fluid">
		<div class="row">

			{% include 'sidebars/sidebar_objects.html' %}

			<div class="col-12 col-lg-10" id="core_content">

                <div class="card my-3">

                    <div class="card-header" style="background-color:#d9edf7;font-size: 15px">
                        <h4 class="text-secondary">{{ chat_instance["protocol"] }} :</h4>
                        <ul class="list-group mb-2">
                            <li class="list-group-item py-0">
                                <table class="table">
                                    <thead>
                                    <tr>
                                        <th>Chat Instance</th>
                                        <th>Network</th>
                                        <th>Address</th>
                                        <th>Nb Chats</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr>
                                        <td>
                                            {{ chat_instance["uuid"] }}
                                        </td>
                                        <td>{% if chat_instance["network"] %}{{ chat_instance["network"]}}{% endif %}</td>
                                        <td>{% if chat_instance["address"] %}{{ chat_instance["address"] }}{% endif %}</td>
                                        <td>{{ chat_instance["chats"] | length }}</td>
                                    </tr>
                                    </tbody>
                                </table>
                            </li>
                        </ul>

                    </div>
                </div>

                <table id="tablechats" class="table table-striped table-bordered">
                    <thead class="bg-dark text-white">
                    <tr>
                        <th>Icon</th>
                        <th>ID</th>
                        <th>Name</th>
                        <th>Username</th>
                        <th>Created at</th>
                        <th>First Seen</th>
                        <th>Last Seen</th>
                        <th>SubChannels</th>
                        <th><i class="fas fa-comment-dots"></i></th>
                    </tr>
                    </thead>
                    <tbody style="font-size: 15px;">
                    {% for chat in chat_instance["chats"] %}
                        <tr>
                            <td>
                                <img src="{% if chat['icon'] %}{{ url_for('objects_image.image', filename=chat['icon'])}}{% else %}{{ url_for('static', filename='image/ail-icon.png') }}{% endif %}"
                                     class="rounded-circle mr-1" alt="{{ chat['id'] }}" width="40" height="40">
                            </td>
                            <td><a href="{{ url_for('chats_explorer.chats_explorer_chat') }}?subtype={{ chat_instance['uuid'] }}&id={{ chat['id'] }}">{{ chat['id'] }}</a></td>
                            <td>
                                <b>{{ chat['name'] }}</b>
                                <div>
                                    {% for tag in chat['tags'] %}
                                        <span class="badge badge-{{ bootstrap_label[loop.index0 % 5] }}">{{ tag }}</span>
                                    {% endfor %}
                                </div>
                            </td>
                            <td>
                                {% if chat['username'] %}
                                    {{ chat['username'] }}
                                {% endif %}
                            </td>
                            <td>{{ chat['created_at'] }}</td>
                            <td>
                                {% if chat['first_seen'] %}
                                    {{ chat['first_seen'][0:4] }}-{{ chat['first_seen'][4:6] }}-{{ chat['first_seen'][6:8] }}
                                {% endif %}
                            </td>
							<td>
                                {% if chat['last_seen'] %}
                                    {{ chat['last_seen'][0:4] }}-{{ chat['last_seen'][4:6] }}-{{ chat['last_seen'][6:8] }}
                                {% endif %}
                            </td>
                            <td>{{ chat['nb_subchannels'] }}</td>
                            <td>{{ chat['nb_messages'] }}</td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>

            </div>

        </div>
    </div>

<script>
    $(document).ready(function(){
        $("#page-Decoded").addClass("active");
        $("#nav_explorer_chat").addClass("active");

        $('#tablechats').DataTable({
            "aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]],
            "iDisplayLength": 10,
            "order": [[ 6, "desc" ]]
        });
  });

function toggle_sidebar(){
	if($('#nav_menu').is(':visible')){
		$('#nav_menu').hide();
		$('#side_menu').removeClass('border-right')
		$('#side_menu').removeClass('col-lg-2')
		$('#core_content').removeClass('col-lg-10')
	}else{
		$('#nav_menu').show();
		$('#side_menu').addClass('border-right')
		$('#side_menu').addClass('col-lg-2')
		$('#core_content').addClass('col-lg-10')
	}
}
</script>

</body>

</html>
